<template>
  <div class="wrapper">
    <div class="bg"></div>
    <van-nav-bar title="帮助中心">
      <template #left>
        <van-icon
          name="arrow-left"
          class="icon"
          size="20"
          @click="onClickLeft"
        />
      </template>
    </van-nav-bar>
    <div class="container">
      <div class="tilte">留言</div>
      <div class="item item1">
        <div class="label">留言用户：</div>
        <div class="data">
          <input
            type="text"
            placeholder="请输入内容"
            name="username"
            v-model="commentData.username"
          />
        </div>
      </div>
      <div class="item">
        <div class="label">电话：</div>
        <div class="data">
          <input
            type="text"
            placeholder="请输入内容"
            name="phone"
            v-model="commentData.phone"
          />
        </div>
      </div>
      <div class="item">
        <div class="label">意见反馈：</div>
        <div class="data">
          <textarea
            name="content"
            id=""
            cols="30"
            rows="10"
            placeholder="请输入内容"
            v-model="commentData.content"
          ></textarea>
        </div>
      </div>
      <div class="btn">
        <van-button color="#5a78ec" round class="button" block @click="toPost"
          >提交</van-button
        >
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      commentData: {
        username: "",
        phone: "",
        content: "",
      },
    };
  },
  methods: {
    async toPost() {
      let res = await this.$http({
        url: "/comment",
        method: "POST",
        data: {
          ...this.commentData,
        },
      });
      if (res.status !== 200) {
        this.$toast.fail({
          message: "发表失败",
        });
        return;
      }
      this.$router.push("/saylist");
      this.$toast.success({
        message: res.message,
      });
      console.log(res);
    },
    onClickLeft() {
      this.$router.back();
    },
  },
};
</script>

<style scoped>
input {
  color: #646468;
}
textarea {
  color: #646468;
}
.icon {
  color: #808080;
}
.bg {
  width: 100%;
  height: 100%;
  position: fixed;
  left: 0;
  top: 0;
  z-index: -1;
  background-color: #dedddd;
}
.container {
  background-color: #ffffff;
  border-radius: 1rem;
  position: fixed;
  left: 50%;
  top: 50%;
  width: 87%;
  transform: translate(-50%, -50%);
}
.tilte {
  text-align: center;
  color: #6d88ee;
  font-size: 1.2rem;
  font-weight: 600;
  margin-top: 1.5rem;
}
.item {
  margin: 0 auto;
  width: 90%;
}
.item1 {
  margin-top: 2rem;
}
.item .label {
  color: #5a78ec;
  font-weight: 550;
  font-size: 0.6rem;
  margin: 0.5rem 0;
}

.item .data input {
  border: 0.0625rem solid #afafaf;
  border-radius: 0.625rem;
  padding: 0.3125rem;
  height: 2.5rem;
  box-sizing: border-box;
  width: 100%;
}
.item .data textarea {
  border: 0.0625rem solid #afafaf;
  border-radius: 0.625rem;
  padding: 0.3125rem;
  height: 6.25rem;
  box-sizing: border-box;
  width: 100%;
}
.btn {
  display: flex;
  justify-content: center;
  margin: 1.7rem 0;
}
.button {
  width: 35%;
  font-size: 1rem;
  border-radius: 1rem;
}
</style>